//
//  YCNewsCell.m
//  YCSchool
//
//  Created by yanglinxia on 16/4/28.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//

#import "YCNewsCell.h"

@interface YCNewsCell ()

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UIImageView *newsImageView;

@property (weak, nonatomic) IBOutlet UILabel *websiteLabel;

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imagVIewHeihgtContranst;

@end

@implementation YCNewsCell

- (void)awakeFromNib {
    // Initialization code
    
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.textColor = [UIColor blackColor];
    
    self.websiteLabel.font = [UIFont systemFontOfSize:9];
    self.websiteLabel.textColor = [UIColor yc_colorWithUInt:0x1a1a1a];
    
    self.timeLabel.font = [UIFont systemFontOfSize:9];
    self.timeLabel.textColor = [UIColor yc_colorWithUInt:0x1a1a1a];
    
    self.newsImageView.image = [UIImage yc_placeHolderImageForSize:CGSizeMake(164.5, 132)];
    
    self.imagVIewHeihgtContranst.constant = iPhone6?132:heightFromIphone6Height(125);//132
    
}


- (void)setItemModel:(YCNewsModel *)itemModel
{
    _itemModel = itemModel;
    
    // 设置标题
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
    style.firstLineHeadIndent = 0;//首行缩进
    style.lineSpacing = 6;//行距
    style.alignment = NSTextAlignmentLeft;
    
    NSAttributedString * textValue = [[NSAttributedString alloc]initWithString:itemModel.title attributes:@{NSParagraphStyleAttributeName:style,
                           NSForegroundColorAttributeName:[UIColor yc_colorWithUInt:0x1a1a1a],
                                                                                                            }];
    
    self.titleLabel.attributedText = textValue;
    
    // 设置来自哪
    self.websiteLabel.text = itemModel.comefromWebsite;

    // 设置显示时间
    if (itemModel.time < 60) { // 小于一分钟
        self.timeLabel.text = [NSString stringWithFormat:@"%zd秒前",itemModel.time];
    } else if (itemModel.time < 60*60) { //小于1小时
        self.timeLabel.text = [NSString stringWithFormat:@"%zd分钟前",itemModel.time / 60];
    } else if (itemModel.time < 60 * 60 * 24) { // 小于一天
        self.timeLabel.text = [NSString stringWithFormat:@"%zd小时前",itemModel.time / 60 /  60];
    }
    // 设置图片
    [self.newsImageView yc_setWebImageWithURLString:itemModel.icon holderSize:CGSizeMake(164.5, 132)];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}




@end
